package com.azt.front.action.index;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.azt.api.pojo.Channel;
import com.azt.api.pojo.Content;
import com.azt.api.service.ChannelService;
import com.azt.api.service.ContentService;
import com.azt.model.AjaxJson;

@Controller
@RequestMapping("/sysfoot")
public class FootAction {
	  
	  @Autowired
	  ChannelService channelService;
	  
	  @Autowired
	  ContentService conentService;
		
	  @RequestMapping("/helpCenter")
	  public String toHelpcenter(Model model){
		  List<Channel> channelList=channelService.getChannelListByParentCode("helpCenter");
		  model.addAttribute("channels", channelList);
		  return "employee/wenTi";
	  }
	  
	  @RequestMapping("/getContentByid")
	  @ResponseBody
	  public AjaxJson getContentByid(Integer id){
		  AjaxJson aj=new AjaxJson();
		  try {
			 Content content=conentService.getContentById(id);
			 Map<String, Object> attr=new HashMap<String,Object>();
			 attr.put("content", content);
			 aj.setAttributes(attr);
			 conentService.doaddReadCount(id);
		  } catch (Exception e) {
			 e.printStackTrace();
			 aj=AjaxJson.error("数据请求失败");
		  }
		  return aj;
	  }
	  
	  @RequestMapping("/doaddOrMinHelp")
	  @ResponseBody
	  public AjaxJson doaddOrMinHelp(String ishelpfulOrhelpless,Integer id){
		  AjaxJson aj=new AjaxJson();
		  try {
			   conentService.doaddOrMinHelp(ishelpfulOrhelpless, id);
		  }catch (Exception e) {
			   e.printStackTrace();
			   aj=AjaxJson.error("点赞失败");
		  }
		  return aj;
	  }
	  
	  @ResponseBody
	  @RequestMapping("/getContentByText")
	  public ModelAndView getContentByText(ModelAndView model,String text){
		  List<Content> contents=conentService.selectContentByTitle(text);
		  model.addObject("contents", contents);
		  model.addObject("searchText", text);
		  model.addObject("searchCount", contents.size());
		  model.setViewName("employee/wentiRes");
		  return model;
	  }
	  
	  @RequestMapping("/zindex")
	  public String textControl(){
		  return "employee/testindex";
	  }
}
